package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Specialskill;
import com.ruoyi.system.service.ISpecialskillService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 特殊工种Controller
 * 
 * @author WEI&WU
 * @date 2024-05-25
 */
@RestController
@RequestMapping("/system/specialskill")
public class SpecialskillController extends BaseController
{
    @Autowired
    private ISpecialskillService specialskillService;

    /**
     * 查询特殊工种列表
     */
    @PreAuthorize("@ss.hasPermi('system:specialskill:list')")
    @GetMapping("/list")
    public TableDataInfo list(Specialskill specialskill)
    {
        startPage();
        List<Specialskill> list = specialskillService.selectSpecialskillList(specialskill);
        return getDataTable(list);
    }

    /**
     * 导出特殊工种列表
     */
    @PreAuthorize("@ss.hasPermi('system:specialskill:export')")
    @Log(title = "特殊工种", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Specialskill specialskill)
    {
        List<Specialskill> list = specialskillService.selectSpecialskillList(specialskill);
        ExcelUtil<Specialskill> util = new ExcelUtil<Specialskill>(Specialskill.class);
        util.exportExcel(response, list, "特殊工种数据");
    }

    /**
     * 获取特殊工种详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:specialskill:query')")
    @GetMapping(value = "/{certificateId}")
    public AjaxResult getInfo(@PathVariable("certificateId") String certificateId)
    {
        return success(specialskillService.selectSpecialskillByCertificateId(certificateId));
    }

    /**
     * 新增特殊工种
     */
    @PreAuthorize("@ss.hasPermi('system:specialskill:add')")
    @Log(title = "特殊工种", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Specialskill specialskill)
    {
        return toAjax(specialskillService.insertSpecialskill(specialskill));
    }

    /**
     * 修改特殊工种
     */
    @PreAuthorize("@ss.hasPermi('system:specialskill:edit')")
    @Log(title = "特殊工种", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Specialskill specialskill)
    {
        return toAjax(specialskillService.updateSpecialskill(specialskill));
    }

    /**
     * 删除特殊工种
     */
    @PreAuthorize("@ss.hasPermi('system:specialskill:remove')")
    @Log(title = "特殊工种", businessType = BusinessType.DELETE)
	@DeleteMapping("/{certificateIds}")
    public AjaxResult remove(@PathVariable String[] certificateIds)
    {
        return toAjax(specialskillService.deleteSpecialskillByCertificateIds(certificateIds));
    }
}
